package ntd.util.frame.task.handle.fm.bo;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.Data;

/**
 * 富铭 - 数据记录 - 规则
 */
@Data
public class FmDataRecordRule {

    private String ruleId;
    private String ruleName;
    private String mn;
    private String factorCode;
    private String factorName;
    private Double eMin = -999999D;
    private Double eMax = 999999D;
    private Double oMin = -999999D;
    private Double oMax = 999999D;
    private Double aMin = -999999D;
    private Double aMax = 999999D;

    /**
     * 根据mn及因子编码构建唯一标识
     * @return
     */
    public String buildKeyOfMnAndFactoryCode() {
        return getMn() + getFactorCode();
    }

    public int isE(double val) {
        if (ObjectUtil.isNotNull(eMin) && NumberUtil.compare(val, eMin) < 0) {
            return -1;
        }
        if (ObjectUtil.isNotNull(eMax) && NumberUtil.compare(val, eMax) > 0) {
            return 1;
        }
        return 0;
    }

    public int isO(double val) {
        if (ObjectUtil.isNotNull(oMin) && NumberUtil.compare(val, oMin) < 0) {
            return -1;
        }
        if (ObjectUtil.isNotNull(oMax) && NumberUtil.compare(val, oMax) > 0) {
            return 1;
        }
        return 0;
    }

    public int isA(double val) {
        if (ObjectUtil.isNotNull(aMin) && NumberUtil.compare(val, aMin) < 0) {
            return -1;
        }
        if (ObjectUtil.isNotNull(aMax) && NumberUtil.compare(val, aMax) > 0) {
            return 1;
        }
        return 0;
    }

}
